Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/repository/src/commonMain/kotlin/org/meshtastic/core/repository/NodeManager.kt 4f86b91973784e4ec05b9a5c7b2dc396ed4848b8 (4f86b919) Text, 8.96 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.repository

Tff7b72import T7ee787kotlinx.coroutines.flow.StateFlow
Tff7b72import T7ee787org.meshtastic.core.model.MyNodeInfo
Tff7b72import T7ee787org.meshtastic.core.model.Node
Tff7b72import T7ee787org.meshtastic.core.model.util.NodeIdLookup
Tff7b72import T7ee787org.meshtastic.proto.DeviceMetadata
Tff7b72import T7ee787org.meshtastic.proto.FirmwareEdition
Tff7b72import T7ee787org.meshtastic.proto.Paxcount
Tff7b72import T7ee787org.meshtastic.proto.StatusMessage
Tff7b72import T7ee787org.meshtastic.proto.Telemetry
Tff7b72import T7ee787org.meshtastic.proto.User
Tff7b72import T7ee787org.meshtastic.proto.NodeInfo Tff7b72as Te6edf3ProtoNodeInfo
Tff7b72import T7ee787org.meshtastic.proto.Position Tff7b72as Te6edf3ProtoPosition

T8b949e/**
* Fresh-handshake identity for one connection session. Separate from the general [NodeManager.myNodeNum]/
* [NodeManager.myDeviceId] StateFlows, which can retain stale cached values across transport switches. [address],
* [nodeNum], and [deviceId] are captured from one selected transport and one MyNodeInfo handshake so consumers never
* have to combine independently delivered address and identity flows. [sessionGeneration] is the active transport
* session generation at handshake time, so the association collector can discard an identity retained from a previous
* transport instance even if every other field is equal.
*/
Tff7b72data Tff7b72class T56d364ConnectionIdentityTb4b4b4(
Tff7b72val Te6edf3sessionGenerationTb4b4b4: Tffa657LongTb4b4b4,
Tff7b72val Te6edf3addressTb4b4b4: Tffa657StringTb4b4b4,
Tff7b72val Te6edf3nodeNumTb4b4b4: Tffa657IntTb4b4b4,
Tff7b72val Te6edf3deviceIdTb4b4b4: Tffa657String?Tb4b4b4,
Tb4b4b4) Tb4b4b4{
T8b949e/** Privacy-safe diagnostic form: neither the transport address nor factory-burned device ID may enter logs. */
Tff7b72override Tff7b72fun Td2a8fftoStringTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657String Tff7b72= Ta5d6ff"Ta5d6ffConnectionIdentity(sessionGeneration=Tffd700$Te6edf3sessionGenerationTa5d6ff, address=..., Ta5d6ff" Tff7b72+
Ta5d6ff"Ta5d6ffnodeNum=Tffd700$Te6edf3nodeNumTa5d6ff, deviceIdPresent=Tffd700${Te6edf3deviceId Tff7b72!Tff7b72= Tff7b72nullTffd700}Ta5d6ff)Ta5d6ff"
Tb4b4b4}

T8b949e/** Interface for managing the in-memory node database and processing received node information. */
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooManyFunctionsTa5d6ff"Tb4b4b4)
Tff7b72interface T56d364NodeManager Tb4b4b4: Te6edf3NodeIdLookup Tb4b4b4{
T8b949e/** Reactive map of all nodes by their number. */
Tff7b72val Te6edf3nodeDBbyNodeNumTb4b4b4: Te6edf3MapTff7b72<Tffa657IntTb4b4b4, Te6edf3NodeTff7b72>

T8b949e/** Look up a node by its user ID string (e.g. `"!a1b2c3d4"`). */
Tff7b72fun Td2a8ffgetNodeByIdTb4b4b4(Te6edf3idTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Te6edf3Node?

T8b949e/** Whether the node database is ready. */
Tff7b72val Te6edf3isNodeDbReadyTb4b4b4: Te6edf3StateFlowTff7b72<Tffa657BooleanTff7b72>

T8b949e/** Sets whether the node database is ready. */
Tff7b72fun Td2a8ffsetNodeDbReadyTb4b4b4(Te6edf3readyTb4b4b4: Tffa657BooleanTb4b4b4)

T8b949e/** Whether node database writes are allowed. */
Tff7b72val Te6edf3allowNodeDbWritesTb4b4b4: Te6edf3StateFlowTff7b72<Tffa657BooleanTff7b72>

T8b949e/** Sets whether node database writes are allowed. */
Tff7b72fun Td2a8ffsetAllowNodeDbWritesTb4b4b4(Te6edf3allowedTb4b4b4: Tffa657BooleanTb4b4b4)

T8b949e/** The local node number as a thread-safe [StateFlow]. */
Tff7b72val Te6edf3myNodeNumTb4b4b4: Te6edf3StateFlowTff7b72<Tffa657Int?Tff7b72>

T8b949e/** Sets the local node number. */
Tff7b72fun Td2a8ffsetMyNodeNumTb4b4b4(Te6edf3numTb4b4b4: Tffa657Int?Tb4b4b4)

T8b949e/**
* The connected device's factory-burned hardware id from MyNodeInfo, as a thread-safe [StateFlow]. Null when not
* connected or when the hardware/firmware doesn't report one. Unlike [myNodeNum] (which firmware 2.8 re-derives
* from the public key), this survives upgrades, erases, and key changes.
*/
Tff7b72val Te6edf3myDeviceIdTb4b4b4: Te6edf3StateFlowTff7b72<Tffa657String?Tff7b72>

T8b949e/** Sets the connected device's hardware id. */
Tff7b72fun Td2a8ffsetMyDeviceIdTb4b4b4(Te6edf3idTb4b4b4: Tffa657String?Tb4b4b4)

T8b949e/** The firmware edition reported by the connected device. */
Tff7b72val Te6edf3firmwareEditionTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3FirmwareEdition?Tff7b72>

T8b949e/** Sets the firmware edition of the connected device. */
Tff7b72fun Td2a8ffsetFirmwareEditionTb4b4b4(Te6edf3editionTb4b4b4: Te6edf3FirmwareEdition?Tb4b4b4)

T8b949e/**
* Fresh-handshake identity for the current connection session. Null when no handshake identity has been confirmed
* for the active transport. Cleared synchronously before a new address is published, and populated atomically when
* [handleMyInfo] captures the selected address and decodes nodeNum and deviceId from the same MyNodeInfo packet.
* Generation-boundary cleanup atomically preserves an identity already published for the new session. Never
* populated by [loadCachedNodeDB] or reactive DB cache emissions.
*/
Tff7b72val Te6edf3connectionIdentityTb4b4b4: Te6edf3StateFlowTff7b72<Te6edf3ConnectionIdentity?Tff7b72>

T8b949e/** Clears the connection-session identity source synchronously. */
Tff7b72fun Td2a8ffclearConnectionIdentityTb4b4b4(Tb4b4b4)

T8b949e/**
* Atomically clears an identity retained from a generation other than [activeSessionGeneration]. An identity that
* already belongs to the active generation is preserved, even when its publication races a delayed boundary
* collector from the same generation.
*/
Tff7b72fun Td2a8ffclearStaleConnectionIdentityTb4b4b4(Te6edf3activeSessionGenerationTb4b4b4: Tffa657LongTb4b4b4)

T8b949e/**
* Publishes a fresh connection-session identity from a handshake MyNodeInfo. Invoked exactly once per handshake
* after [sessionGeneration], [address], [nodeNum], and [deviceId] have been captured for the same session.
*/
Tff7b72fun Td2a8ffpublishConnectionIdentityTb4b4b4(Te6edf3sessionGenerationTb4b4b4: Tffa657LongTb4b4b4, Te6edf3addressTb4b4b4: Tffa657StringTb4b4b4, Te6edf3nodeNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3deviceIdTb4b4b4: Tffa657String?Tb4b4b4)

T8b949e/** Loads the cached node database from the repository. */
Tff7b72fun Td2a8ffloadCachedNodeDBTb4b4b4(Tb4b4b4)

T8b949e/** Clears the in-memory node database. */
Tff7b72fun Td2a8ffclearTb4b4b4(Tb4b4b4)

T8b949e/** Returns information about the local node. */
Tff7b72fun Td2a8ffgetMyNodeInfoTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3MyNodeInfo?

T8b949e/** Returns the local node ID. */
Tff7b72fun Td2a8ffgetMyIdTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657String

T8b949e/** Processes a received user packet. */
Tff7b72fun Td2a8ffhandleReceivedUserTb4b4b4(
Te6edf3fromNumTb4b4b4: Tffa657IntTb4b4b4,
Te6edf3pTb4b4b4: Te6edf3UserTb4b4b4,
Te6edf3channelTb4b4b4: Tffa657Int Tff7b72= T79c0ff0Tb4b4b4,
Te6edf3manuallyVerifiedTb4b4b4: Tffa657Boolean Tff7b72= Tff7b72falseTb4b4b4,
Te6edf3sessionTb4b4b4: Te6edf3RadioSessionContext? Tff7b72= Tff7b72nullTb4b4b4,
Tb4b4b4)

T8b949e/** Processes a received position packet. */
Tff7b72fun Td2a8ffhandleReceivedPositionTb4b4b4(
Te6edf3fromNumTb4b4b4: Tffa657IntTb4b4b4,
Te6edf3myNodeNumTb4b4b4: Tffa657IntTb4b4b4,
Te6edf3pTb4b4b4: Te6edf3ProtoPositionTb4b4b4,
Te6edf3defaultTimeTb4b4b4: Tffa657LongTb4b4b4,
Te6edf3sessionTb4b4b4: Te6edf3RadioSessionContext? Tff7b72= Tff7b72nullTb4b4b4,
Tb4b4b4)

T8b949e/** Processes a received telemetry packet. */
Tff7b72fun Td2a8ffhandleReceivedTelemetryTb4b4b4(Te6edf3fromNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3telemetryTb4b4b4: Te6edf3TelemetryTb4b4b4)

T8b949e/** Processes a received paxcounter packet. */
Tff7b72fun Td2a8ffhandleReceivedPaxcounterTb4b4b4(Te6edf3fromNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3pTb4b4b4: Te6edf3PaxcountTb4b4b4, Te6edf3sessionTb4b4b4: Te6edf3RadioSessionContext? Tff7b72= Tff7b72nullTb4b4b4)

T8b949e/** Processes a received node status message. */
Tff7b72fun Td2a8ffhandleReceivedNodeStatusTb4b4b4(Te6edf3fromNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3sTb4b4b4: Te6edf3StatusMessageTb4b4b4, Te6edf3sessionTb4b4b4: Te6edf3RadioSessionContext? Tff7b72= Tff7b72nullTb4b4b4)

T8b949e/** Updates the status string for a node. */
Tff7b72fun Td2a8ffupdateNodeStatusTb4b4b4(Te6edf3nodeNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3statusTb4b4b4: Tffa657String?Tb4b4b4)

T8b949e/** Updates node status and awaits any required persistence. */
Tff7b72suspend Tff7b72fun Td2a8ffupdateNodeStatusAndPersistTb4b4b4(Te6edf3nodeNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3statusTb4b4b4: Tffa657String?Tb4b4b4)

T8b949e/**
* Updates a node using a side-effect-free [transform] and schedules persistence. The transform may be evaluated
* more than once after compare-and-set contention; callers must perform notifications and other effects afterward.
*/
Tff7b72fun Td2a8ffupdateNodeTb4b4b4(Te6edf3nodeNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3channelTb4b4b4: Tffa657Int Tff7b72= T79c0ff0Tb4b4b4, Te6edf3transformTb4b4b4: Tb4b4b4(Te6edf3NodeTb4b4b4) Tff7b72-Tff7b72> Te6edf3NodeTb4b4b4)

T8b949e/** Session-bound counterpart to [updateNode]; deferred persistence is admitted only for [session]. */
Tff7b72fun Td2a8ffupdateNodeForSessionTb4b4b4(Te6edf3nodeNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3sessionTb4b4b4: Te6edf3RadioSessionContextTb4b4b4, Te6edf3channelTb4b4b4: Tffa657Int Tff7b72= T79c0ff0Tb4b4b4, Te6edf3transformTb4b4b4: Tb4b4b4(Te6edf3NodeTb4b4b4) Tff7b72-Tff7b72> Te6edf3NodeTb4b4b4)

T8b949e/**
* Updates a node using a side-effect-free [transform] and awaits any required persistence before returning. The
* transform may be evaluated more than once after compare-and-set contention.
*
* Session-scoped packet processing uses this while holding transport authority so an old session cannot enqueue a
* database write that resumes after a device switch. Non-session UI and controller updates continue to use
* [updateNode].
*/
Tff7b72suspend Tff7b72fun Td2a8ffupdateNodeAndPersistTb4b4b4(Te6edf3nodeNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3channelTb4b4b4: Tffa657Int Tff7b72= T79c0ff0Tb4b4b4, Te6edf3transformTb4b4b4: Tb4b4b4(Te6edf3NodeTb4b4b4) Tff7b72-Tff7b72> Te6edf3NodeTb4b4b4)

T8b949e/** Removes a node from the in-memory database by its number. */
Tff7b72fun Td2a8ffremoveByNodenumTb4b4b4(Te6edf3nodeNumTb4b4b4: Tffa657IntTb4b4b4)

T8b949e/**
* Applies node-number removals returned by the trusted configuration install. Removed numbers stay retired for the
* current device/database session so delayed field packets cannot recreate migrated identities.
*/
Tff7b72fun Td2a8ffapplyTrustedIdentityMigrationsTb4b4b4(Te6edf3removedNumsTb4b4b4: Te6edf3CollectionTff7b72<Tffa657IntTff7b72>Tb4b4b4)

T8b949e/**
* Installs node information in memory. Callers that require an immediate standalone write use
* [installNodeInfoAndPersist]; configuration handshakes batch the resulting snapshot through the repository.
*/
Tff7b72fun Td2a8ffinstallNodeInfoTb4b4b4(Te6edf3infoTb4b4b4: Te6edf3ProtoNodeInfoTb4b4b4)

T8b949e/** Installs node information and awaits any required persistence. */
Tff7b72suspend Tff7b72fun Td2a8ffinstallNodeInfoAndPersistTb4b4b4(Te6edf3infoTb4b4b4: Te6edf3ProtoNodeInfoTb4b4b4)

T8b949e/** Inserts hardware metadata for a node. */
Tff7b72fun Td2a8ffinsertMetadataTb4b4b4(Te6edf3nodeNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3metadataTb4b4b4: Te6edf3DeviceMetadataTb4b4b4, Te6edf3sessionTb4b4b4: Te6edf3RadioSessionContext? Tff7b72= Tff7b72nullTb4b4b4)
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.06s